/*******************************************************************************
 * Copyright (c) Jonathan Buck - jonbuck16@gmail.com
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    jonbuck16@gmail.com - initial API and implementation
 *******************************************************************************/
package net.jonbuck.tassoo.persistence.ui.wizard;

import net.jonbuck.tassoo.model.Tassoo;
import net.jonbuck.tassoo.model.TassooFactory;
import net.jonbuck.tassoo.model.TassooPackage;
import net.jonbuck.tassoo.persistence.dao.TassooDao;
import net.jonbuck.tassoo.persistence.dao.TassooDaoImpl;
import net.jonbuck.tassoo.persistence.exception.TassooCreationException;
import net.jonbuck.tassoo.persistence.ui.wizard.model.NewTaskStore;
import net.jonbuck.tassoo.persistence.ui.wizard.page.TaskStoreDetailsPage;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;

/**
 * 
 * 
 * @since 1.0.0
 */
public class NewTaskStoreWizard extends Wizard implements INewWizard {

	/** Model for the wizard. */
	private NewTaskStore newTaskStore;

	/** Tassoo Data Access Object. */
	private TassooDao tassooDao = TassooDaoImpl.getInstance();

	private TassooPackage tassooPackage;

	private TassooFactory tassooFactory;

	/**
	 * 
	 */
	public NewTaskStoreWizard() {
		super();
	}

	/**
	 * 
	 */
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		newTaskStore = new NewTaskStore();
		tassooPackage = TassooPackage.eINSTANCE;
		tassooFactory = tassooPackage.getTassooFactory();
	}

	/**
	 * 
	 */
	public void addPages() {
		addPage(new TaskStoreDetailsPage(TaskStoreDetailsPage.PAGE_NAME, newTaskStore));
	}

	/**
	 * 
	 */
	public boolean performFinish() {
		try {
			Tassoo tassoo = tassooFactory.createTassoo();
			tassoo.setName(newTaskStore.getTaskStoreName());
			tassoo.setFilePath(newTaskStore.getFilePath());
			tassoo.setDescription(newTaskStore.getDescription());
			tassooDao.createNewTaskStore(tassoo);
			
			
			
		} catch (TassooCreationException tce) {
			// TODO Handle Exception here...
			System.out.println(tce.getMessage());
			return false;
		}
		return true;
	}

}
